package com.sx.manage.service.consumer.util;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sx.common.util.http.constants.BasicAccountType;
import com.sx.common.util.http.constants.PaperType;
import com.sx.common.util.message.EMailMessageModel;
import com.sx.common.util.message.MessageModel;
import com.sx.common.util.message.MessageType;
import com.sx.common.util.message.ShortMessageModel;
import com.sx.model.constants.type.FieldConstants;
import com.sx.model.manage.mybatis.vo.biz.center.MAccountVO;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerBankMapVO;
import com.sx.model.manage.mybatis.vo.consumer.MConsumerEditDetailVO;
import com.sx.model.manage.mybatis.vo.consumer.MPersonalConsumerVO;

/**
 * service impl 辅助类
 * 
 * @author lenovo
 *
 */
public class WebConsumerEditUtil {
	// 系统日志添加
	public static Logger logger = LoggerFactory.getLogger(WebConsumerEditUtil.class);
	/** 用户修改数据转换为 华夏人员审核数据**/
	public static List<MConsumerEditDetailVO> editInfoDetailForHuaXiaData(List<MConsumerEditDetailVO> dataList) {
		logger.debug("用户修改数据转换为 华夏人员审核数据dataList={}",dataList);
		List<MConsumerEditDetailVO> returnList = new ArrayList<>();
		for (MConsumerEditDetailVO detailVO : dataList) {
			switch (String.valueOf(detailVO.getEdit_field_english())) {
			case FieldConstants.CONSUMER_BANK_BANK_CONSUMER_NAME:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_BANK_ID:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_BANK_NAME:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_CARD_NUM:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_CITY_ID:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_CITY_NAME:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_CLS_BANK_CODE:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_BANK_CLS_BANK_NAME:
				returnList.add(detailVO);
				break;
			default:
				break;
			}
		}
		return returnList;
	}
	/** 用户修改数据转换为后台人员审核数据**/
	public static List<MConsumerEditDetailVO> editInfoDetailForSystemConsumer(List<MConsumerEditDetailVO> dataList) {
		logger.debug("用户修改数据转换为后台人员审核数据dataList={}",dataList);
		List<MConsumerEditDetailVO> returnList = new ArrayList<>();
		for (MConsumerEditDetailVO detailVO : dataList) {
			switch (String.valueOf(detailVO.getEdit_field_english())) {
			case FieldConstants.CONSUMER_CONSUMER_NAME:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_EMAIL:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_LAW_NO:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_LAW_TYPE:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_MOBILE_TEL:
				returnList.add(detailVO);
				break;
			case FieldConstants.CONSUMER_NATIONALITY:
				returnList.add(detailVO);
				break;
			default: break;
			}
		}
		return returnList;
	}
	
	/**
	 * 短信组件-组装ShortMessageModel
	 * 
	 * @param phone
	 * @param tplId
	 * @param tplValue
	 * @param userId
	 * @return
	 */
	public static MessageModel get_shortMessage(String phone, Long tplId, Object[] tplValue, String userId, MessageType messageType) {
		ShortMessageModel shortMessage = new ShortMessageModel();
		shortMessage.setTplId(String.valueOf(tplId));
		shortMessage.setMessage(tplValue);
		MessageModel message = new MessageModel();
		message.setUseid(userId);
		message.setUsername(null);
		message.setPhone(phone);
		message.setShortmessagemodel(shortMessage);
		message.setMessagetype(messageType);
		return message;
	}
	/**
	 * 邮件组件-组装EMailMessageModel
	 * 
	 * @param email
	 * @param temail
	 * @param emialsub
	 * @param emialcontent
	 * @param userId
	 * @param messageType
	 * @return
	 */
	public static MessageModel get_emailMessage(String email, String temail, String emialsub, String emialcontent, String userId, MessageType messageType) {
		EMailMessageModel eMailMessage = new EMailMessageModel();
		// 发送邮件地址
		eMailMessage.setEmail(email);
		// 接收方邮件地址
		eMailMessage.setTemail(temail);
		// 邮件主题
		eMailMessage.setEmialsub(emialsub);
		// 邮件正文
		eMailMessage.setEmialcontent(emialcontent);
		MessageModel message = new MessageModel();
		message.setUseid(userId);
		message.setEmailmessagemodel(eMailMessage);
		message.setMessagetype(messageType);
		return message;
	}
	/**
	 * 短信参数拼接
	 * 
	 * @param userName
	 * @param url
	 * @return
	 */
	public static String spelArg(String userName, String url) {
		// 短信格式 "#user#=朱万民&#url#=https://www.baidu.com"
		if (null == userName) {
			return null;
		}
		if (null == url) {
			return null;
		}
		return "#user#=" + userName + "&#url#=" + url;
	}
	/**
	 * 激活参数
	 * 
	 * @param emailCode
	 * @param values
	 * @return
	 */
	public static String formatValues(String emailCode, Object... values) {
		if (null == values || null == emailCode) {
			return null;
		}
		String text = null;
		text = String.format(emailCode, values);

		return text;
	}
	/**
	 * 转换 证件类型
	 * 
	 * @param papersType
	 * @return
	 */
	public static PaperType verifyPapersType(String papersType) {
		PaperType pt = null;
		// IDENTITYCARD 身份证IDENTITYCARD
		if ("identitycard".equals(papersType)) {
			pt = PaperType.IDENTITYCARD;
			// SOLDIERCARD 军官证
		} else if ("police".equals(papersType)) {
			pt = PaperType.SOLDIERCARD;
			// FAMILYREGISTER 户口本
		} else if ("household".equals(papersType)) {
			pt = PaperType.HOUSEHOLD;
			// PASSPORT 护照
		} else if ("passport".equals(papersType)) {
			pt = PaperType.PASSPORT;
			// TEMPPAPER 临时身份证
		} else if ("temporary".equals(papersType)) {
			pt = PaperType.TEMPORARY;
			// OTHER 其他
		} else {
			pt = PaperType.OTHER;
		}
		return pt;
	}
	/**
	 * 封装 MAccountVO 对象
	 * 
	 * @param company
	 * @param userBankMap
	 * @param paperType
	 * @return
	 */

	public static MAccountVO saveAccountInfo(MPersonalConsumerVO personalVO, MConsumerBankMapVO consumerBankMapVO) {
		if (null == personalVO || null == consumerBankMapVO) {
			return null;
		}
		MAccountVO accountVO = new MAccountVO();
		accountVO.setUserId(personalVO.getId());
		accountVO.setBankCode(consumerBankMapVO.getBank_code());// personalVO.getBank().getBank_info().getBank_code()
		accountVO.setAccountName(consumerBankMapVO.getBank_consumer_name());// personalVO.getBank().getBank_consumer_name()
		accountVO.setMobile(personalVO.getMobile_tel());
		accountVO.setAccountType(BasicAccountType.PERSONAL);//
		accountVO.setPaperType(PaperType.IDENTITYCARD);

		accountVO.setPaperNo(personalVO.getLaw_no());
		accountVO.setRelaAcct(consumerBankMapVO.getCard_num());// personalVO.getBank().getCard_num()
		accountVO.setRelaAcctName(consumerBankMapVO.getBank_consumer_name());// personalVO.getBank().getBank_consumer_name()
		accountVO.setRelaAcctBank(consumerBankMapVO.getCls_bank_name());// personalVO.getBank().getCls_bank_name()
		// 地址 有详细地址改为，支行名称
		accountVO.setRelaAcctBankAddr(consumerBankMapVO.getBank_name());// personalVO.getBank().getBank_info().getBank_name()
		accountVO.setRelaAcctBankCode(consumerBankMapVO.getBank_code());// personalVO.getBank().getBank_info().getBank_code()
		accountVO.setEmail(personalVO.getEmail());
		accountVO.setPhone(personalVO.getOffice_tel());
		accountVO.setClsBankName(consumerBankMapVO.getCls_bank_name());// personalVO.getBank().getCls_bank_name()
		accountVO.setClsBankCode(consumerBankMapVO.getCls_bank_code());// personalVO.getBank().getCls_bank_code()
		logger.info("==================paperType=" + personalVO.getLaw_type());
		logger.info("==================开户ID开户全部信息:" + "companyId=" + personalVO.getId() + "basicAccountType=" + BasicAccountType.PERSONAL + "accountName=" + consumerBankMapVO.getBank_consumer_name() + "paperNo=" + personalVO.getLaw_no() + "relaAcct=" + consumerBankMapVO.getCard_num() + "relaAcctName="
				+ consumerBankMapVO.getBank_consumer_name() + "relaAcctBank=" + consumerBankMapVO.getCls_bank_name() + "relaAcctBankAddr=" + consumerBankMapVO.getProvince_name() + consumerBankMapVO.getCity_name() + consumerBankMapVO.getBank_name() + "relaAcctBankCode="
				+ consumerBankMapVO.getBank_code() + "email=" + personalVO.getEmail() + "mobile" + personalVO.getMobile_tel() + "clsBankName:" + consumerBankMapVO.getCls_bank_name() + "clsBankCode:" + consumerBankMapVO.getCls_bank_code());

		return accountVO;
	}

}
